import java.util.Arrays;

/**
 * @ClassName LC1991
 * @Author ykx
 * @Date 2024/7/13 10:44
 * @Version 1.0
 */
public class LC1991 {
    public static void main(String[] args) {
        int[] ints = {-5, 1, -5};
        LC1991 lc1991 = new LC1991();
        System.out.println(lc1991.findMiddleIndex(ints));
    }

    public int findMiddleIndex(int[] nums) {
        int sum = Arrays.stream(nums).sum();
        int result = -1;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] % 2 * nums[i] % 2 != sum % 2 * sum % 2) {
            } else {
                if (Arrays.stream(nums, 0, i).sum() == Arrays.stream(nums, i + 1, nums.length).sum()) {
                    return i;
                }
            }
        }
        return result;
    }
}
